package com.zyj.java1;

import sun.misc.Launcher;
import sun.security.ec.CurveDB;

import java.net.URL;
import java.security.Provider;
import java.sql.DriverManager;

/**
 * @program: JVMDemo
 * @ClassName ClassLoaderTest1
 * @author: YaJun
 * @Date: 2021 - 12 - 02 - 11:23
 * @Package: com.zyj.java1
 * @Description: 获取ClassLoader的途径
 */
public class ClassLoaderTest2 {

    public static void main(String[] args) {

        try {
            // 0. 获取当前类的ClassLoader
            ClassLoader classLoader1 = ClassLoaderTest2.class.getClassLoader();
            System.out.println(classLoader1);   // sun.misc.Launcher$AppClassLoader@18b4aac2    系统类加载器
            // 1. 获取指定类的ClassLoader
            ClassLoader classLoader = Class.forName("java.lang.String").getClassLoader();
            System.out.println(classLoader);    // null 引导类加载器

            // 2. 获取当前线程上下文的ClassLoader
            ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
            System.out.println(contextClassLoader); // sun.misc.Launcher$AppClassLoader@18b4aac2    系统类加载器

            // 3. 获取系统的ClassLoader
            ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
            System.out.println(systemClassLoader);  // sun.misc.Launcher$AppClassLoader@18b4aac2    系统类加载器

            // 4. 获取调用者的ClassLoader

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


    }

}
